package leetcode.动态规划;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/8/20 20:40
 * @description：https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/
 */
public class 买卖股票的最佳时机II {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.maxProfit(new int[]{7, 1, 5, 3, 6, 4}));
    }

    class Solution {
        public int maxProfit(int[] prices) {
            int ans = 0;
            for (int i = 1; i < prices.length; i++) {
                ans += Math.max(0, prices[i] - prices[i - 1]);
            }
            return ans;
        }
    }
}
